﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="AnagraficaArticoliCliente.aspx.cs" Inherits="FimetContoDeposito.Anagrafiche.AnagraficaArticoliCliente" %>

<%@ Register assembly="GrayParrot.Web.Controls" namespace="GrayParrot.Web.Controls" tagprefix="cc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <asp:PlaceHolder ID="PlaceHolder1" runat="server">        
        <%: Styles.Render("~/bundles/Datatables/css") %>
        <%: Scripts.Render("~/bundles/Datatables") %>
        <%: Styles.Render("~/bundles/Formly/css") %>
        <%: Scripts.Render("~/bundles/Formly") %>
    </asp:PlaceHolder>

    <script type="text/javascript" lang="javascript" src="../Scripts/Formly/FormlyHelper.js"></script>
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.Core.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.AngularJS.Directives.Fileupload.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.AngularJS.Directives.DateTimePicker.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.AngularJS.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.DataTables.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.Modals.js"></script> 
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <section class="panel">
	    <header class="panel-heading">
			<b id="titolo">Anagrafica Articoli</b>
		</header>

<%--        <a class="collapsed" data-toggle="collapse" href="#collapseSetting">
            <h4 class="fa  fa-search"> Filters</h4>
        </a>
        <section id="collapseSetting" class="collapse" style="height: 0px;">
            <div class="collapse-boby" style="padding:0">
                <% HttpContext.Current.Response.Write(this.JQDTable.RenderExternalFilters()); %>
            </div>
        </section>--%>

		<%--<div class="panel-body">--%>

            <!-- PUT YOUR CONTENT HERE -->
                <iframe id='iframeCrud' frameborder="0" style="width:1000px; height:550px; display:none"></iframe>
                <div id="crudDialog" title="" style="display:none"></div>
                <div id="deleteDiv" title="" style="display:none"></div>

                <input type="hidden" id="mag" name="mag" />

                <%--<div class="row">--%>
<%--                    <div class="col-lg-12">--%>
                        <%--<section class="panel"> --%> 
                            <div class="panel-body">
                                <cc1:JQDataTable ID="JQDTable" runat="server" 
                                     SelectionMode="Single" 
                                     RenderScripts="false" 
                                     BootstrapClasses="table table-hover table-bordered table-condensed compact">
                                    <FeaturesConfig>
                                        <Features>
                                            <cc1:Searching Value="None">
                                                <Filters>
                                                    <cc1:ColumnFilter ColumnName="Codice" Type="Text" />
                                                    <cc1:ColumnFilter ColumnName="Descrizione" Type="Text" />
                                                </Filters>
                                            </cc1:Searching>
                                            <cc1:AutoWitdh Value="true" />
                                            <cc1:ScrollY Value="500" ScrollCollapse="true" />
                                            <cc1:LengthChange Value="false" />
                                            <cc1:Paging PagingType="FullNumbers" PageLength="20" />
                                        </Features>
                                    </FeaturesConfig>
                                    <ControllerConfig Url="/api/AnagraficaArticoli/LoadArticolimagazzinoCliente" LoadingMode="OnLoad">
                                        <ControllerParameters>
                                            <cc1:ControllerParameter Name="mag" Alias="Customer" />
                                        </ControllerParameters>
                                    </ControllerConfig>
                                    <ColumnsConfig Key="Id">
                                        <Columns>
                                            <cc1:TextColumn Name="Id" Header="Id" Visible="false" />
                                            <cc1:TextColumn Name="DescrCliente" Header="Magazzino" />
                                            <cc1:TextColumn Name="Codice" Header="Codice" />
                                            <cc1:TextColumn Name="Descrizione" Header="Descrizione" />
                                            <cc1:TextColumn Name="DescrUnitaDiMisura" Header="U. Misura" />
                                            <cc1:TextColumn Name="IsAbilitato" Header="Abilitato" />
                                            <cc1:TextColumn Name="DescrTipologia" Header="Tipo" />
                                            <cc1:TextColumn Name="PesoTeorico" Header="P. Teorico" Width="10"  />
                                            <cc1:TextColumn Name="ScortaMinima" Header="Scorta Min." Width="10" />
                                            <cc1:TextColumn Name="PrezzoUnitario" Header="P. Unitario" Width="10" />
                                            <cc1:TextColumn Name="ScontoFornitore" Header="Sconto" Width="10" />
                                            <cc1:TextColumn Name="IdCliente" Header="IdCliente" Visible="false" />
                                            <cc1:ActionColumn >
                                                <Actions>
                                                    <cc1:ActionIcon Icon="fa fa-search" Callback="ShowImage" />
                                                    <cc1:ActionIcon Icon="fa fa-pencil" Callback="EditCallback" />
                                                    <cc1:ActionIcon Icon="fa fa-trash-o" Callback="DeleteCallback" />
                                                </Actions>
                                            </cc1:ActionColumn>
                                        </Columns>
                                    </ColumnsConfig>
                                    <Toolbar>
                                        <cc1:IconButton Icon="fa-plus" Callback="LoadAddDialog" />
                                    </Toolbar>
                                </cc1:JQDataTable>
                            </div>                      
                        <%--</section>--%>
                    <%--</div>--%>
                <%--</div>--%>
		<%--</div>--%>
	</section>

</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="LocaJavascript" runat="server">
    <% HttpContext.Current.Response.Write(this.JQDTable.RenderScriptsManually()); %>

<script>
    $(document).ready(function () {
        // BOOTSTRAP: Tweaks
        $('.yadcf-filter-wrapper').addClass('input-group');
        $('.yadcf-filter, .yadcf-filter-date', this).addClass('form-control input-sm');
        $('.yadcf-filter-reset-button', this).addClass('btn btn-default btn-sm').wrap('<span class="input-group-btn"></span>');

        GetMagazzino();
    });

    function GetMagazzino() {
        //$('#mag').val('A1152C6E-1A32-4A48-8C1D-31CABA42A841');

        var m_id_magazzino = $('#mag').val();

        if ((m_id_magazzino === undefined) || (m_id_magazzino == '')) {
            var url = '/api/AnagraficaArticoli/GetMagazzinoFormUser';

            $.ajax({
                type: "GET",
                url: url,
                data: null,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    $('#mag').val(response.Customer)
                    $('#titolo').text('Anagrafica Articoli ' + response.Azienda);

                    RedrawGrid(m_tableJQDTable);

                    alert(response);
                },
                failure: function (response) {
                    alert(response);
                }
            });
        }
    }

    function ShowImage(obj) {
        //alert(obj.FotoArticolo);

        $("#iframeCrud").prop('src', '/operazioni/ShowImage.aspx?id=' + obj.Id).appendTo("#crudDialog");
        $("#iframeCrud").width(800);
        $("#iframeCrud").height(450);
        $("#iframeCrud").show();

        m_dialog = $("#crudDialog").dialog({
            title: 'Dettaglio Articolo',
            width: 'auto',
            height: 'auto',
            modal: true,
            close: function () {
                $("#iframeCrud").width(1000);
                $("#iframeCrud").height(550);
                $("#iframeCrud").contents().remove();
                $('#iframeCrud').hide();
            }
        });
    }

    function CloseDialog(response) {
        $('#crudDialog').dialog('close');

        alert(response);
    }

    function LoadAddDialog() {

        var m_id_magazzino = $('#mag').val();
        m_id_magazzino = m_id_magazzino.replace('string:', '');

        $("#iframeCrud").prop('src', 'AnagraficaArticoli_CRUD.aspx?idMg=' + m_id_magazzino).appendTo("#crudDialog");
        $("#iframeCrud").show();

        m_dialog = $("#crudDialog").dialog({
            title: 'Anagrafica Articoli',
            width: 'auto',
            height: 'auto',
            modal: true,
            close: function () {
                RedrawGrid(m_tableJQDTable);

                $("#iframeCrud").contents().remove();
                $('#iframeCrud').hide();
            }
        });
    }

    function EditCallback(obj) {
        var p = null;
        p = obj.Id;

        var m_id_magazzino = $('#mag').val();
        m_id_magazzino = m_id_magazzino.replace('string:', '');

        var url = 'AnagraficaArticoli_CRUD.aspx?id=' + p + '&idMg=' + m_id_magazzino;

        $("#iframeCrud").prop('src', url).appendTo("#crudDialog");
        $("#iframeCrud").show();

        m_dialog = $("#crudDialog").dialog({
            title: 'Anagrafica Articoli',
            width: 'auto',
            height: 'auto',
            modal: true,
            close: function () {
                RedrawGrid(m_tableJQDTable);

                $("#iframeCrud").contents().remove();
                $('#iframeCrud').hide();
            }
        });
    }

    function DeleteCallback(obj) {
        var p = null;
        p = obj.Id;

        var url = '/api/AnagraficaArticoli/Delete';

        $("#deleteDiv").contents().remove();
        $("#deleteDiv").html("Confermi la cancellazione dell'elemento con codice: " + p + " ?").appendTo("#crudDialog");
        //$("#crudDialog").html("Confermi la cancellazione dell'elemento con codice: " + p + " ?");
        $("#deleteDiv").show();

        // Define the Dialog and its properties.
        $("#crudDialog").dialog({
            resizable: false,
            modal: true,
            title: "Cancella elemento",
            height: 250,
            width: 400,
            buttons:[
            {
                id: "Yes",
                text: "Si",
                click: function () {
                    $(this).dialog("option", { buttons: {} });
                    //$(this).empty();
                    $(this).dialog('close');

                    $.ajax({
                        type: "POST",
                        url: url,
                        data: JSON.stringify({ id: p }),
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (response) {
                            RedrawGrid(m_tableJQDTable);

                            //$("#crudDialog").html('');
                            $("#deleteDiv").contents().remove();
                            $('#deleteDiv').hide();

                            alert(response);
                        },
                        failure: function (response) {

                            //$("#crudDialog").empty();
                            $("#deleteDiv").contents().remove();
                            $('#deleteDiv').hide();

                            alert(response);
                        }
                    });
                }
            },
            {
                id: "No",
                text: "No",
                click: function () {
                    //$("#crudDialog").empty();
                    $("#deleteDiv").contents().remove();
                    $('#deleteDiv').hide();

                    $(this).dialog('close');
                }
            }
            ]
        });
    }

    function LoadEditDialog() {

        var p = null;
        p = GetSelectedData(m_tableJQDTable).Id;

        var m_id_magazzino = $('#formly_1_asyncselect_selMagazzini_0').val();
        m_id_magazzino = m_id_magazzino.replace('string:', '');
               
        var url = 'AnagraficaArticoli_CRUD.aspx?id=' + p + '&idMg=' + m_id_magazzino;

        $("#iframeCrud").prop('src', url).appendTo("#crudDialog");
        $("#iframeCrud").show();

        m_dialog = $("#crudDialog").dialog({
            title: 'Anagrafica Articoli',
            width: 'auto',
            height: 'auto',
            modal: true,
            close: function () {
                RedrawGrid(m_tableJQDTable);

                $("#iframeCrud").contents().remove();
                $('#iframeCrud').hide();
            }
        });
    }

    function DeleteDialog() {
        var p = null;

        var row = GetSelectedData(m_tableJQDTable);

        p = row.Id;

        var url = '/api/AnagraficaArticoli/Delete';

        $("#deleteDiv").contents().remove();
        $("#deleteDiv").html("Confermi la cancellazione dell'elemento con codice: " + p + " ?").appendTo("#crudDialog");
        //$("#crudDialog").html("Confermi la cancellazione dell'elemento con codice: " + p + " ?");
        $("#deleteDiv").show();

        // Define the Dialog and its properties.
        $("#crudDialog").dialog({
            resizable: false,
            modal: true,
            title: "Cancella elemento",
            height: 250,
            width: 400,
            buttons:[
                {
                    id: "Yes",
                    text: "Si",
                    click: function () {
                        $(this).dialog("option", { buttons: {} });
                        //$(this).empty();
                        $(this).dialog('close');

                        $.ajax({
                            type: "POST",
                            url: url,
                            data: JSON.stringify({ id: p }),
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function (response) {
                                RedrawGrid(m_tableJQDTable);

                                //$("#crudDialog").html('');
                                $("#deleteDiv").contents().remove();
                                $('#deleteDiv').hide();

                                alert(response);
                            },
                            failure: function (response) {

                                //$("#crudDialog").empty();
                                $("#deleteDiv").contents().remove();
                                $('#deleteDiv').hide();

                                alert(response);
                            }
                        });
                    }
                },
                {
                    id: "No",
                    text: "No",
                    click: function () {
                        //$("#crudDialog").empty();
                        $("#deleteDiv").contents().remove();
                        $('#deleteDiv').hide();

                        $(this).dialog('close');
                    }
                }
            ]
        });
    }
</script>
</asp:Content>